package com.example;

import javax.sql.DataSource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import com.alibaba.druid.pool.DruidDataSource;
@SpringBootApplication
@ComponentScan
public class DemoApplication  extends SpringBootServletInitializer{
        /** 
         * 实现SpringBootServletInitializer可以让spring-boot项目在web容器中运行 
         */  
        @Override  
        protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {  
            builder.sources(this.getClass());  
            return super.configure(builder);  
        }  

        
        @Bean 
        @ConfigurationProperties(prefix="spring.datasource")
    public DataSource druidDataSource() {
            return new DruidDataSource();
        }
        
	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}
}
